<%@ include file="../../inc/init.jsp" %>

<html>
	<head>
		<title>
			Graduate Admission System | University of California - San Diego | 
			Applicant Overview 
		</title>
		<link type="text/css" rel="stylesheet" href="<%= BASE %>css/main.css">
		<script type="text/javascript" src="<%= BASE %>js/msg.js"></script>
	</head>
	<body <%
	
		/** Show javascript message if msg parameter is set **/
	
		if(request.getParameter("msg") != null)
		{
			int msg = Integer.parseInt(request.getParameter("msg"));
			out.println("onload = \"info(" + msg + ", 5, " + BASE + ")\"");
		}

	%>>
		<div class="header-top"></div>
		<div class="header">
			<a href="<%= BASE %>index.jsp"><img src="<%= BASE %>img/logo.png"></a>
		</div>
		<div class="content">
		<br>
		<table>
		<tr><td><a href="<%= BASE %>applicant/index.jsp">
				<img src="<%= BASE %>img/home.png"></a>&nbsp;&nbsp;
			</td>
			<td><span style="color: #515151;">You are logged in as: <b><%= request.getRemoteUser() %></b></span>&nbsp;</td>
			<td><a href="<%= BASE %>logout.jsp">
				<img src="<%= BASE %>img/logout.png"></a>
			</td>
		</tr>
		</table><br>
		
		<div id="message"></div>
		
		<%
			Applicant a = new Applicant();
			int applicantId = a.getApplicantId(request.getRemoteUser());
		
			/** Generate Link **/
			
			if(request.getParameter("generate") != null)
			{				
				String generatedLink = LetterOfRecommendation.generateLink(applicantId);
				
				if(generatedLink != null && !generatedLink.equals("Fail"))
				{
					response.sendRedirect("index.jsp?msg=103");
				}
				else
				{
					response.sendRedirect("index.jsp?msg=205");
				}
			}
		
		%>
		
		Click <a href="index.jsp?generate=link">here</a> to generate a new link.
			
		<h2>Active links:</h2>
		
		<%	
			/** Show active links **/
		
			if(LetterOfRecommendation.getActiveLinks(applicantId).size() == 0)
			{
				out.print("There are no active links at the moment. Click on the link above to generate one.");
			}
			else
			{
				out.print("<table class=\"border3D\">");
				
				for(int i = 0; i < LetterOfRecommendation.getActiveLinks(applicantId).size(); i++)
				{
					if(i%2 == 0)
					{
						out.print("<tr class=\"evenHover\" style=\"text-align: left;\"><td>");
					}
					else
					{
						out.print("<tr class=\"oddHover\" style=\"text-align: left;\"><td>");
					}
					
					out.print(LetterOfRecommendation.getActiveLinks(applicantId).get(i) + "</td></tr>");
				}
				
				out.print("</table>");
			}
		%>
		
		<h2>Received Letter of Recommendations:</h2>
		
		<%	
			/** Show received letter of recommendations **/
		
			if(LetterOfRecommendation.getLetters(applicantId).size() == 0)
			{
				out.print("You have not received any letter of recommendation yet.");
			}
			else
			{
				out.print("<table class=\"border\"><th>Title</th><th>First Name</th><th>Name</th><th>Institute</th><th>Options</th>");
				
				for(int i = 0; i < LetterOfRecommendation.getLetters(applicantId).size(); i++)
				{
					if(i%2 == 0)
					{
						out.print("<tr class=\"evenHover\"><td>");
					}
					else
					{
						out.print("<tr class=\"oddHover\"><td>");
					}
					
					out.print(LetterOfRecommendation.getLetters(applicantId).get(i).getTitle() + "</td><td>" +
							  LetterOfRecommendation.getLetters(applicantId).get(i).getFirstName() + "</td><td>" +
							  LetterOfRecommendation.getLetters(applicantId).get(i).getName() + "</td><td>" +
							  LetterOfRecommendation.getLetters(applicantId).get(i).getInstitute() + "</td><td></tr>");
				}
				
				out.print("</table>");
			}
		%>
		
		</div>
	</body>
</html>